package day12;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author oldliu
 * @since 1.0
 */
public class MyServer1 {
    public static void main(String[] args) {
        try {
            //1024-65535
            ServerSocket st=new ServerSocket(9996);
            System.out.println("服务器监听9996端口");
            while (true){
                Socket s = st.accept();
                System.out.println(s+"连上了");
                System.out.println("ip:"+s.getInetAddress()+",端口："+s.getPort());
                System.out.println("本地："+s.getLocalAddress()+",本地端口："+s.getLocalPort());
                InputStream in = s.getInputStream();
                OutputStream out = s.getOutputStream();
                System.out.println("avaialble:"+in.available());
                int ch=0;
                while ((ch=in.read())!=-1){
                    System.out.print((char)ch);
                }
                s.close();///
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
